ERROR = 1
WARNING = 2
DEBUG = 3
local LogLevel = 3

ModEditor = {}

function ModEditor.Log(msg,code)
	if code > LogLevel then
		return
	end
	if code == ERROR then
		echo("Error: "..msg)
	elseif code == WARNING then
		echo("Warning: "..msg)
	elseif code == INFORMATION then
		echo("Information: "..msg)
	else
		echo(msg)
	end
end
function ModEditor.SafeCall(func,msg,...)
	local result,retval = pcall(func,...)
	if result then
		return true,retval
	else
		if msg ~= nil then
			ModEditor.Log(msg,ERROR)
		end
		echo(retval)
		return false,retval
	end
end
local dofile_old = dofile
function dofile(fname)
	ModEditor.SafeCall(dofile_old,"Can't load \""..fname.."\" script:",fname)
end

local function SetupEverything()
	ModEditor.Internal = {}
	ModEditor.Input = {}
	ModEditor.Input.Internal = {}
	ModEditor.GUI = {}
	ModEditor.Camera = {}
	ModEditor.Windows = {}
	
	ModEditor.Version = {0,1,0,ReleaseType = "Prealpha"}
	
	ModEditor.Internal.MouseButtonPressed = false
	ModEditor.Input.MouseX = 200
	ModEditor.Input.MouseY = 200
	ModEditor.Input.RightCtrl = false
	ModEditor.Input.LeftCtrl = false
	ModEditor.Input.RightShift = false
	ModEditor.Input.LeftShift = false
	ModEditor.Input.KeyHook = nil
	ModEditor.Input.Keys = {}
	ModEditor.ObjectList = {}
	--Object:
	-- -Type:
	--  1 = Box
	--  2 = Sphere
	--  3 = Capsule
	--
	-- -Size {X/Y/Z}
	-- -Rot {X/Y/Z}
	-- -Pos {X/Y/Z}
	-- -Color {A/R/G/B}
	-- -Name
	ModEditor.Mode = 1
	-- 1 = Object Moving Mode
	-- 2 = Object Rotating Mode

	dofile("modeditor/eventmgr.lua")
	dofile("slgui/windowlist.lua")
	dofile("slgui/basicwindow.lua")
	dofile("slgui/basiccontrol.lua")
	dofile("slgui/controls.lua")
	dofile("modeditor/addobject.lua")
	dofile("modeditor/renameobject.lua")
	dofile("modeditor/modcontrol.lua")
	dofile("modeditor/objectcontrol.lua")
	dofile("modeditor/cameracontrol.lua")
	dofile("modeditor/base.lua")
end

ModEditor.SafeCall(SetupEverything)
ModEditor.SafeCall(ModEditor.Internal.SetupHooks)
ModEditor.SafeCall(ModEditor.Internal.Start)
